<%@ page language="java" import="java.util.*,com.jpf.demo.*" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 商品列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
        <li> <a class="button border-main icon-plus-square-o" href="add.jsp"> 添加商品</a> </li>
        <li>搜索：</li>
        <li>
        <form method="post" class="form-x" action="QueryGoods.do"> 
        </li>
        <li>
          <input type="text" placeholder="请输入商品名称" name="gname" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <button class="button bg-main icon-check-square-o" type="submit"> 搜索</button></li>
          </form>
      </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th width="100" style="text-align:left; padding-left:20px;">商品编号</th>
        <th width="10%">商品价格</th>
        <th>商品图片</th>
        <th>商品名称</th>
        <th>品牌</th>
        <th>库存</th>
        <th>类别</th>
        <th width="10%">上架时间</th>
        <th width="310">操作</th>
      </tr>
      <volist name="list" id="vo">
      <c:forEach items="${goodsList.pageRow}" var="goods">
      <tr>
          <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="id[]" value="${goods.gid}" />${goods.gid}</td>
          <td>${goods.gprice}</td>
          <td width="10%"><img src="goodsimage/${goods.gimage}" alt="" width="70" height="50" /></td>
          <td>${goods.gname}</td>
          <td>${goods.brand}</td>
          <td><font color="#00CC99">${goods.gstock}</font></td>
          <td>${goods.cid}</td>
          <td>${goods.shelftime}</td>
          <td><div class="button-group"> <a class="button border-main" href="AlterGoods.do?gid=${goods.gid}"><span class="icon-edit"></span> 查看</a> <a class="button border-red" href="javascript:void(0)" onclick="return del(${goods.gid})"><span class="icon-trash-o"></span> 删除</a> </div></td>
        </tr>
      </c:forEach>
       <tr>
        <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>
          全选 </td>
        <td colspan="8" style="text-align:left;padding-left:20px;"><a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" onclick="DelSelect()"> 删除</a>
          &nbsp;&nbsp;&nbsp;
      </tr>
      <tr>
      <td colspan="11"><div class="pagelist"> 
        <!-- 分页模块=>注意：判断是否头（begin）溢出和尾（end）溢出 -->
	<c:out value="第${goodsList.pageNow}页/共${goodsList.pageCount}页"></c:out>
	<c:if test="${goodsList.pageNow > 1}">
		<a href="<c:url value="ShowList.do?pageNow=${1}" />" class="numberPage">首页</a>
		<a href="<c:url value="ShowList.do?pageNow=${goodsList.pageNow-1}" />" class="numberPage">上一页</a>
	</c:if>
	<!-- 
		总页数小于要显示的页数（5页）
			begin（起始页码） = 1；
			end（末尾页码） = ${goodsList.pageCount}；
		总页数大于要显示的页数（5页）
			begin = ${goodsList.pageNow - 2 }；
			end = ${goodsList.pageNow - 2 }；
	 -->
	<c:choose>
		<c:when test="${goodsList.pageCount < goodsList.pageSize }">
			<c:set var="begin" value="1" />
			<c:set var="end" value="${goodsList.pageCount}" />
		</c:when>
		<c:otherwise>
			<c:set var="begin" value="${goodsList.pageNow - 2 }" />
			<c:set var="end" value="${goodsList.pageNow + 2 }" />
			<c:if test="${begin < 1 }">
				<c:set var="begin" value="${1}" />
				<c:set var="end" value="${5}" />
			</c:if>
			<c:if test="${end > goodsList.pageCount }">
				<c:set var="begin" value="${goodsList.pageCount-4}" />
				<c:set var="end" value="${goodsList.pageCount}" />
			</c:if>
		</c:otherwise>
	</c:choose>
	<%-- 循环打印页码（i），如果${i eq goodsList.pageNow }则取消超链接 --%>
	<c:forEach var="i" begin="${begin }" end="${end }">
		<c:choose>
			<c:when test="${i eq goodsList.pageNow }">
				${i}
			</c:when>
			<c:otherwise>
				<a href="<c:url value="ShowList.do?pageNow=${i}" />" class="numberPage">${i}</a>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	<c:if test="${goodsList.pageNow < goodsList.pageCount}">
		<a href="<c:url value="ShowList.do?pageNow=${goodsList.pageNow+1}" />" class="numberPage">下一页</a>
		<a href="<c:url value="ShowList.do?pageNow=${goodsList.pageCount}" />" class="numberPage">尾页</a>
	</c:if>
	</div></td>
      </tr>
    </table>
  </div>
<script type="text/javascript">

//单个删除
function del(gid){
	if(confirm("您确定要删除吗?")){
		location.href="DeleteGoods.do?action=search&gid="+gid;
	}
}

//全选
$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

//批量删除
function DelSelect(){
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  	}
	  });
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;		
		else{
		 var checkedList = new Array();
         $("input[name='id[]']:checked").each(function(){
         checkedList.push($(this).val());
         });
         $.ajax({
         type:"POST",
         url:"DeleteGoods.do",
         data:{"delgoods":checkedList.toString()},
         datatype:"html",
         success:function(data){
         	$("[name='checkbox2']:checkbox").attr("checked",false);
            location.href="QueryGoods.do ";//页面刷新
            },
         error:function(data){
            art.dialog.tips('删除失败!');
            }
         });
		}	
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

</script>
</body>
</html>